//
//  RMMEvaluaSkillTableViewCell.m
//  Romomo
//
//  Created by puman on 2016/10/25.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMEvaluaSkillTableViewCell.h"

@implementation RMMEvaluaSkillTableViewCell{
    UIImageView *_imageV;
    UILabel *_nameLabel;
    UILabel *_yearLabel;
    UIImageView *_scoreImageV;
    UILabel *_scoreLabel;

}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(15, 12.5, 50, 50)];
        _imageV.layer.masksToBounds = YES;
        _imageV.layer.cornerRadius = 25;
        [self.contentView addSubview:_imageV];
        
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_imageV.right + 15, _imageV.top, 60, 30)];
        _nameLabel.font = kBFont(16);
        [self.contentView addSubview:_nameLabel];
        
        
        _yearLabel = [[UILabel alloc] initWithFrame:CGRectMake(_nameLabel.right + 8, _nameLabel.top + 6, 40, 18)];
        _yearLabel.textColor = kWhiteColor;
        _yearLabel.backgroundColor = RGBA(236, 194, 66, 1);
        _yearLabel.textAlignment = NSTextAlignmentCenter;
        _yearLabel.font = kBFont(12);
        _yearLabel.layer.masksToBounds = YES;
        _yearLabel.layer.cornerRadius = 3;
        [self.contentView addSubview:_yearLabel];
        
        for (int i = 0; i  < 5; i++) {
            UIImageView *iamgeView = [[UIImageView alloc] initWithFrame:CGRectMake(_nameLabel.left + 20 * i, _nameLabel.bottom + 2.5 , 15, 15)];
            iamgeView.image = [UIImage imageNamed:@"星1-2@3x"];
            iamgeView.tag = 10000 + i;
            [self.contentView addSubview:iamgeView];
        }
        _scoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(_imageV.right + 115, _nameLabel.bottom + 5, 40, 12)];
        _scoreLabel.textColor = COLORFROMCODE(0x9B9B9B , 1);
        _scoreLabel.font = kFont(10);
        [self.contentView addSubview:_scoreLabel];
    }
    return self;
}
- (void)setDic:(NSDictionary *)dic{
    _scoreLabel.text = [NSString stringWithFormat:@"%@分",[RMMFileManager retrunObjWith:dic[@"SVA_SCORE"]]];
    _nameLabel.text = [RMMFileManager retrunObjWith:dic[@"EMP_IMAGE"][@"EMP_NAME"]];
    _yearLabel.text =  [NSString stringWithFormat:@"%@年",[RMMFileManager retrunObjWith:dic[@"ANNUAL_LEAVE"]]];
    [_imageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kBaseImageUrl,[RMMFileManager retrunObjWith:dic[@"EMP_IMAGE"][@"EMP_IMAGE_URL"]]]] placeholderImage:[UIImage imageNamed:@"加载中@3x"]];
    CGFloat width = [UILabel backHeightWithString:_nameLabel.text CGFloatCount:25 metho:WIDTH font:16];
    _nameLabel.frame = CGRectMake(_imageV.right + 15, _imageV.top, width, 25);
    CGFloat widthY = [UILabel backHeightWithString:_yearLabel.text CGFloatCount:18 metho:WIDTH font:12];
    _yearLabel.frame =  CGRectMake(_nameLabel.right + 8, _nameLabel.top + 3.5, widthY + 10, 18);
    [self setStarWith:[RMMFileManager retrunObjWith:dic[@"SVA_SCORE"]]];
}
- (void)setStarWith:(NSString *)score{
    NSInteger s1 = [score integerValue];
    CGFloat s2 = [score floatValue];
    for (int i = 0; i < 5; i++) {
        UIImageView *imageV = [self viewWithTag:10000 + i];
        if (i < s1) {
            imageV.image = [UIImage imageNamed:@"星-1@3x"];
        } else {
            if (i >= s1 && i < s2) {
                imageV.image = [UIImage imageNamed:@"星-3@3x"];
            } else {
                imageV.image = [UIImage imageNamed:@"星1-2@3x"];
            }
        }
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
